package com.dhj.methodsTest;

import com.dhj.streamTest.entity.Author;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

import static com.dhj.streamTest.entity.AuthorList.getAuthors;

public class Demo3 {

    public static void main(String[] args) {
        List<Author> authors = getAuthors();

        StringBuilder authorName = new StringBuilder();
        authors.stream().distinct()
                .forEach(new Consumer<Author>() {
                    @Override
                    public void accept(Author author) {
                        authorName.append(author.getName());
                    }
                });
        System.out.println(authorName);


        System.out.println("------------------------------");


        StringBuilder authorName2 = new StringBuilder();
        authors.stream().distinct()
                .map(author -> author.getName())
                .forEach(new Consumer<String>() {
                    @Override
                    public void accept(String name) {
                        authorName2.append(name);
                    }
                });
        System.out.println(authorName2);


        System.out.println("------------------------------");


        StringBuilder authorName3 = new StringBuilder();
        authors.stream().distinct()
                .map(Author::getName)
                .forEach(authorName3::append);
        System.out.println(authorName3);


    }
}
